

// var dataBytes = [0x10, 0x01, 0x00, 0x00,0x90, 0xcf, 0x1b, 0x47,0, 0, 0, 0, 0, 0, 0, 0,0x4d, 0x44, 0x32, 0x30,0x61]
// var dataStart = 1


// var buffer = new ArrayBuffer(12);
// var x = new DataView(buffer, 0);

// console.log(x)

// // var view = new jDataView(dataBytes.slice(), dataStart, undefined, true)
// // var version = view.getInt32(0); // 272
// // var float = view.getFloat32(4); // 39887.5625

// // console.log(view,version,float)

// function str2ab(str) {
// var buf = new ArrayBuffer(str.length*2); // 每个字符占用2个字节
// var bufView = new Uint16Array(buf);
// console.log(bufView,buf)
// for (var i=0, strLen=str.length; i<strLen; i++) {
// bufView[i] = str.charCodeAt(i);
// }
// console.log(buf,bufView)
// return buf;
// }

// str2ab('dsdsa')

// var name = "http://www.example.com";
// var xhrDiv = document.getElementById("xhrDiv");

// var req = new XMLHttpRequest();
// req.open("GET", name, true);
// req.responseType = "arraybuffer";
// req.onreadystatechange = function () {
// if (req.readyState == req.DONE) {

//     var arrayResponse = req.response || new ArrayBuffer()
//     var dataView = new DataView(arrayResponse);
//     var ints = new Uint32Array(dataView.byteLength / 4);

//     xhrDiv.style.backgroundColor = "#00FF00";
//     xhrDiv.innerText = "Array is " + ints.length + "uints long";


//             for (var i = 0; i < ints.length; i++) {
//                 ints[i] = dataview.getInt32(i * 4);
//             }
//         alert(ints[10]);
//     }
// }
// req.send();

function stringToUint(string) {
    var string = btoa(unescape(encodeURIComponent(string))),
        charList = string.split(''),
        uintArray = [];
    for (var i = 0; i < charList.length; i++) {
        uintArray.push(charList[i].charCodeAt(0));
    }
    return new Uint8Array(uintArray);
}

function uintToString(uintArray) {
    var encodedString = String.fromCharCode.apply(null, uintArray),
        decodedString = decodeURIComponent(escape(atob(encodedString)));
    return decodedString;
}


var buffer  = new ArrayBuffer(21)
var dataView = new DataView(buffer,0)

var uint = stringToUint('string')
console.log(uint)
for(var i=0;i<uint.length;i++)
{
	console.log(dataView.byteOffset,dataView.byteLength,dataView.buffer)

	dataView.setUint8(i,uint[i])

}

var Uint8Array =[]

for( var i=0;i<8;i++ )
{
	Uint8Array[Uint8Array.length] = dataView.getUint8(i)
}

console.log( uintToString(Uint8Array) )



// var file = jDataView.createBuffer(
//     0x10, 0x01, 0x00, 0x00, // Int32 - 272
//     0x90, 0xcf, 0x1b, 0x47, // Float32 - 39887.5625
//     0, 0, 0, 0, 0, 0, 0, 0, // 8 blank bytes
//     0x4d, 0x44, 0x32, 0x30, // String - MD20
//     0x61                    // Char - a
// );
















